function filtered_signal = myFilter(signal,cutoff_hz,toAnalyse)
if ~exist('toAnalyse','var') || isempty(toAnalyse)
toAnalyse = 0;
end
%cutoff_hz = 30;
sample_rate = 200;
% Normalize cutoff frequency (wrt Nyquist frequency)
nyq_freq = sample_rate / 2;
cutoff_norm = cutoff_hz / nyq_freq;
 
% FIR filter order (i.e. number of coefficients - 1)
order = 80;

fir_coeff = fir1(order, cutoff_norm);
if(toAnalyse)
  % Analyse the filter using the Filter Visualization Tool
  fvtool(fir_coeff, 'Fs', sample_rate)
end
% Filter the signal with the FIR filter
filtered_signal = filter(fir_coeff, 1, signal);

% % Fs = 200;
% % xdft = fft(signal);
% % % xdft = xdft(1:uint16(length(signal)/2));
% % freq_spectrum = linspace(0,(Fs/2),length(signal));
% % win = zeros(size(xdft));
% % win(:,find(freq_spectrum >cutoff_hz(1),1):find(freq_spectrum >cutoff_hz(2),1)) = 1;
% % x_filt = xdft.*win;
% % %figure;plot(freq_spectrum,xdft,'b',freq_spectrum,x_filt,'r',freq_spectrum,win,'g')
% % filtered_signal = real(ifft(x_filt));
% % %figure;plot(filtered_signal);
end
